const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes');
const errorHandler = require('./middlewares/errorHandler');

const app = express();

// 中间件配置
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// API路由
app.use('/', routes);

// 错误处理中间件
app.use(errorHandler);

// 设置监听端口
const PORT = process.env.PORT || 10086;
app.listen(PORT, () => {
  console.log(`服务器运行在端口 ${PORT}`);
});